require "Common/define"
require "Logic/Config"
require "Common/functions"
require 'View/BattleUI/TeamPartnerInfo'

---@class GuildBossInfo
GuildBossInfo = Class("GuildBossInfo")
function GuildBossInfo:ctor()
    ---@param rankInfo ResUseHeroRankMessage
    self.rankInfo = {};--排行榜数据
    self.bossInfo = {};--boss的信息
    self.rewardsInfo = {};--排行信息
    self.bossCfg = {};--boss配表信息
    self.battleCount = 0;--今日boss战斗次数
    self.bossRefreshTime = 0;--boss刷新时间
    self.formation = { {}, {} };--上次战斗的阵容
end

---@class GuildManager
GuildManager = {};
local this = GuildManager;
this._GuildMarketCost = 3      -- 工会砍价通用货币,金币
this.db_guildlogo = {}         --公会旗帜
this.db_guildlocation = {}     --公会地址信息
this.unionInfo = nil;          --公会信息
this.unionEventLogs = nil;     --公会日志
this.JOB_MEEMBER_ID = 1;       --普通成员ID
this.JOB_VICECHAIRMAN_ID = 2;  --副会长ID
this.JOB_CHAIRMAN_ID = 3;      --会长ID
this.cdTime = 0;               --入会时间戳
this.canClick = true
this.wishChange = 0;       --别人给你捐赠碎片标签 0不弹 1弹
this.applyAllyNum = -1;   --结盟小红点
this.hasAllyApply = false;    --结盟小红点


function GuildManager.init()
    ---@param GuideBossHero table<BattleTeamPartnerInfo>
    this.guideBossHeroes = {};--当前可选的挑战工会boss的英雄
    ---@param guideBossHeroesModel table<number,BattleTeamPartnerInfo>
    this.guideBossHeroesModel = {}--根据modelId存储英雄数据
    ---@param guideBossHeroesPartnerId table<string,BattleTeamPartnerInfo>
    this.guideBossHeroesPartnerId = {}--根据PartnerId存储英雄数据
    this.guildBossInfo = nil;--工会boss信息
    ---@param bossResultReward table<number,number>
    ---bossResultReward{{道具modelid，数量},...}
    this.bossResultReward = {};      --公会boss奖励
    this.bossDamage = 0;    --公会boss总伤害
    this.lastCount = 0;   --上次层数
    ---@param guildForceRankList UnionRankShowInfo
    this.guildForceRankList = {};--公会战力榜数据
    this.selfUnionRank = -1;
    this.selfApplyGuildList = {};--申请的公会
    this.helpManInfos = {};--因为战斗中没有出现替补的会导致替补头像无法显示，提前储存替补信息


    local t_guildlogo = G.dataTable["t_guildlogo"];
    for k, v in pairs(t_guildlogo) do
        this.db_guildlogo[tonumber(k)] = v;
    end
    local t_guildlocation = G.dataTable["t_guildlocation"];
    for k, v in pairs(t_guildlocation) do
        if type(v.f_GuildCity) == "string" then
            v.f_GuildCity = string_split(v.f_GuildCity, ",");
        end
        this.db_guildlocation[tonumber(k)] = v;
    end
    this.taskLivenessCount = 0
    ---@type TaskInfo[]
    this.taskInfoList = {}
    for k, v in pairs(G.dataTable["t_guildtask"]) do
        local oneTaskInfo = {}
        oneTaskInfo["f_GuildTaskId"] = v.f_GuildTaskId
        oneTaskInfo["f_GuildTaskType"] = v.f_GuildTaskType
        oneTaskInfo["f_Progress"] = v.f_Progress
        oneTaskInfo["f_GuildTaskDesc"] = v.f_GuildTaskDesc
        oneTaskInfo["f_ExpCount"] = v.f_ExpCount
        oneTaskInfo["progress"] = 0
        oneTaskInfo["status"] = 1 --0:可领取 1:未完成 2:已领取
        table.insert(this.taskInfoList, oneTaskInfo)
        --this.taskInfoList[v.f_GuildTaskId] = oneTaskInfo
    end
    ---@type LivenessInfo[]
    this.taskLivenessList = {}
    this.allianceInfoList = {};
    this.applyAllyNum = -1;   --结盟小红点
    this.hasAllyApply = false;    --结盟小红点
    this.giftSrvData = {}
    this.giftCfgData = dataTable.getDataTable("t_guildgift")
end
-- 切换账号时会清理
function GuildManager.OnDestroy()
    this.guildMarketIsNotFristOpen = nil;
    if this.resetTaskTimer then
        utimer.remove(this.resetTaskTimer)
        this.resetTaskTimer = nil
    end
end

-- 获取工会配置表里的整数类型
function GuildManager.getGuildParaIntValue(id)
    if id == nil then
        return 0;
    end
    return G.dataTable["t_guildpara"][tostring(id)].f_int_value or 0;
end
-- 获取工会配置表里的字符串类型
function GuildManager.getGuildParaStringValue(id)
    if id == nil then
        return "";
    end
    return G.dataTable["t_guildpara"][tostring(id)].f_string_value or "";
end
---------------------------工会大厅------------开始------------
function GuildManager.getUnionSetting()
    return this.unionInfo and this.unionInfo.unionOutlineInfo.unionSetting or {};
end

function GuildManager.getUnionNotice()
    local unionSetting = GuildManager.getUnionSetting();
    return unionSetting and unionSetting.unionNotice or '';
end

function GuildManager.getUnionId()
    return this.unionInfo and this.unionInfo.id or 0;
end

function GuildManager.getAllianceId()
    --return this.unionInfo and this.unionInfo.allianceId or 0;
    return 0;
end

function GuildManager.getUnionName()
    return this.unionInfo and this.unionInfo.name or '';
end
--获取当前公会成员数量
function GuildManager.getUnionMember()
    return table.getn(this.unionInfo.members);
end

function GuildManager.getFlagId(unionInfo)
    if not unionInfo then
        unionInfo = this.unionInfo;
    end
    if unionInfo and unionInfo.unionOutlineInfo then
        return unionInfo.unionOutlineInfo.unionSetting.flagId;
    end
    return 1;
end

function GuildManager.getUnionTotalForce(unionInfo)
    if not unionInfo then
        unionInfo = this.unionInfo;
    end
    if unionInfo and unionInfo.unionOutlineInfo then
        return unionInfo.unionOutlineInfo.totalForce;
    end
    return 1;
end

function GuildManager.getUnionLv()
    if this.unionInfo and this.unionInfo.unionOutlineInfo then
        return this.unionInfo.unionOutlineInfo.lv;
    end
    return 0;
end

--获取当前公会配置
function GuildManager.getCurLevelGuildCfg()
    local lv = this.getUnionLv();
    local t_guild = G.dataTable["t_guild"];
    for k, v in pairs(t_guild) do
        if v.f_Level == lv then
            return v;
        end
    end
    return nil;
end

--获取下一级升级经验
function GuildManager.getNextLevelExp(lv)
    if not lv then
        lv = this.getUnionLv();
    end

    if lv <= 0 then
        return 1;
    end

    local t_guild = G.dataTable["t_guild"];
    for k, v in pairs(t_guild) do
        if v.f_Level == lv then
            return v.f_Exp;
        end
    end
    return GuildManager.getNextLevelExp(lv - 1);
end

--获取最大成员数目
function GuildManager.getMaxMemberCnt(lv)
    if not lv then
        lv = this.getUnionLv();
    end
    local t_guild = G.dataTable["t_guild"];
    local maxMember = 0;
    for k, v in pairs(t_guild) do
        if v.f_Level == lv then
            return v.f_Number;
        end
        maxMember = math.max(maxMember, v.f_Number);
    end
    return maxMember;
end

function GuildManager.setSelfApplyGuildList(msg, isClear)
    if isClear then
        this.selfApplyGuildList = {};
    end
    for k, v in pairs(msg.unionIds) do
        this.selfApplyGuildList[v] = true;
    end
end

function GuildManager.checkSelfApplyGuildId(id)
    if this.selfApplyGuildList[id] then
        return true;
    end
    return false;
end


--获取还可以申请公会的名额
function GuildManager.getRemainApplyCnt()
    if not this.unionInfo then
        return 0
    end
    return GuildManager.getMaxMemberCnt() - #this.unionInfo.members;
end

--获取当前副会长的
function GuildManager.getCurViceChairmanCnt()
    local cnt = 0;
    if this.unionInfo then
        for _, v in ipairs(this.unionInfo.members) do
            if v.jobId == GuildManager.JOB_VICECHAIRMAN_ID then
                cnt = cnt + 1;
            end
        end
    end
    return cnt;
end

--获取还可以设置副会长的名额
function GuildManager.getRemainViceChairmanCnt()
    if not this.unionInfo then
        return 0
    end
    local guildCfg = GuildManager.getCurLevelGuildCfg();
    if not guildCfg then
        return 0
    end
    return guildCfg.f_VicePresident - GuildManager.getCurViceChairmanCnt();
end

--获取公会成员职称配置和职称Id
function GuildManager.getUnionTitleCfgByPlayerId(playerId)
    local jobId = 0;
    local memberInfo = GuildManager.getMemberInfoByPlayerId(playerId);
    if memberInfo then
        jobId = memberInfo.jobId;
    end
    local t_guildtitle = G.dataTable["t_guildtitle"];
    return G.dataTable["t_guildtitle"][tostring(jobId)], jobId;
end

--获取职称名字
function GuildManager.getUnionTitleByJobId(jobId)
    jobId = jobId or 0;
    if G.dataTable["t_guildtitle"][tostring(jobId)] == nil then
        return "";
    end
    return getLanguage(G.dataTable["t_guildtitle"][tostring(jobId)].f_GuildTitleName);
end

--获取自己在公会内的职称
function GuildManager.getMyUnionTitle()
    local cfg = GuildManager.getUnionTitleCfgByPlayerId(logicMgr.HeroManager.GetRoleInfo().playerId);
    if cfg then
        return getLanguage(cfg.f_GuildTitleName);
    end
    return '';
end


--是否是会长
function GuildManager.isChairman(jobId)
    if not jobId and this.unionInfo then
        return tostring(this.unionInfo.leader.showInfo.playerId) == tostring(logicMgr.HeroManager.GetRoleInfo().playerId);
    end
    return jobId == this.JOB_CHAIRMAN_ID;
end

--是否是副会长
function GuildManager.isViceChairman(jobId)
    if jobId == nil then
        local memberInfo = GuildManager.getMemberInfoByPlayerId(logicMgr.HeroManager.GetRoleId());
        if memberInfo then
            jobId = memberInfo.jobId;
        end
    end
    return jobId == this.JOB_VICECHAIRMAN_ID;
end

--是否有申请公会
function GuildManager.hasApplyGuildMembers()
    if this.unionInfo and #logicMgr.GuildManager.unionInfo.askJoinList > 0 then
        local _, jobId = GuildManager.getUnionTitleCfgByPlayerId();
        return GuildManager.isChairman(jobId) or GuildManager.isViceChairman(jobId); --只有会长和副会长才可以审批
    end
    return false;
end

function GuildManager.canQuitGuild()
    local isChairman = GuildManager.isChairman();
    if isChairman and #this.unionInfo.members > 1 then
        return false;
    end
    return true;
end

function GuildManager.getUnionAddress(unionInfo)
    if not unionInfo then
        unionInfo = this.unionInfo;
    end
    if unionInfo and unionInfo.unionOutlineInfo and unionInfo.unionOutlineInfo.unionSetting then
        return unionInfo.unionOutlineInfo.unionSetting.province .. ' ' .. unionInfo.unionOutlineInfo.unionSetting.city;
    end
    return '';
end

function GuildManager.updateUnionInfo(msg)
    logicMgr.GuildManager.canClick = true
    if not msg or msg.state ~= 0 then
        this.unionInfo = nil;
        if this.unionInfo == nil then
            plunderHandler.ResetUnionHelpData()
        end
        this.cdTime = 0;
    else
        GuildManager.SetUnionProperty(msg.unionInfo)
        this.unionInfo = msg.unionInfo;
        if this.unionInfo == nil then
            plunderHandler.ResetUnionHelpData()
        end
        this.cdTime = msg.cdTime or 0;
    end

    if this.unionInfo then
        this.selfApplyGuildList = {};
        table.sort(this.unionInfo.members, function(a, b)
            if a.jobId ~= b.jobId then
                return a.jobId > b.jobId;
            end
            local aTime = tonumber(tostring(a.offlineTime))
            local bTime = tonumber(tostring(b.offlineTime))
            if (aTime < 1 and bTime > 1) then
                return true;
            elseif (bTime < 1 and aTime > 1) then
                return false;
            elseif (aTime < 1 and bTime < 1) then
                return aTime < bTime;
            else
                return aTime > bTime;
            end
        end);

        --申请上限前端暂时屏蔽到100个
        local cnt = #logicMgr.GuildManager.unionInfo.askJoinList;
        --逆序
        for i = 1, cnt - 1 do
            local left = logicMgr.GuildManager.unionInfo.askJoinList[i];
            logicMgr.GuildManager.unionInfo.askJoinList[i] = logicMgr.GuildManager.unionInfo.askJoinList[cnt - i + 1];
            logicMgr.GuildManager.unionInfo.askJoinList[cnt - i + 1] = left;
        end
        for i = 101, cnt do
            logicMgr.GuildManager.unionInfo.askJoinList[i] = nil;
        end
        if this.applyAllyNum < 0 then
            local applyAllyList = this.unionInfo.askJoinList2;
            if applyAllyList ~= nil and #applyAllyList > 0 then
                this.applyAllyNum = 1;
            end
        end
    end
    FireEvent(Config.EventType.Union_Info_Change);
end

function GuildManager.updateUnionAllianceState(state)
    this.unionInfo.unionOutlineInfo.release = state;
end

function GuildManager.updateUnionSettingInfo(msg)
    if msg.state == 0 then
        this.unionInfo.unionOutlineInfo.unionSetting = msg.unionSetting;
    else

    end
    FireEvent(Config.EventType.Union_Info_Change);
end

function GuildManager.updateUnionName(msg)
    if msg.state == 0 then
        this.unionInfo.unionOutlineInfo.name = msg.unionName;
        this.unionInfo.name = msg.unionName;
    end
    FireEvent(Config.EventType.Union_Info_Change);
end

function GuildManager.updateUnionEventLogs(msg)
    if msg.state == 0 then
        this.unionEventLogs = msg.unionEventLogs;
    end
end

function GuildManager.getFlagUrl(flagIdx)
    if not flagIdx then
        flagIdx = GuildManager.getFlagId();
    end
    local data = GuildManager.db_guildlogo[flagIdx];
    if data and data.f_GuildLogoIcon then
        local iconUrl = "ui://UIGuild/" .. data.f_GuildLogoIcon;
        return iconUrl;
    end
    return data;
end

function GuildManager.getProvinces()
    local t = {}
    for k, v in pairs(this.db_guildlocation) do
        t[k] = v.f_GuildProvince;
    end
    return t;
end

function GuildManager.getProvince(proIdx)
    local datas = GuildManager.getProvinces();
    return datas[proIdx];
end

function GuildManager.getProvinceCitys(proIdx)
    local data = GuildManager.db_guildlocation[proIdx];
    return data.f_GuildCity;
end

function GuildManager.getProvinceCity(proIdx, cityIdx)
    local datas = GuildManager.getProvinceCitys(proIdx);
    return datas[cityIdx];
end

function GuildManager.setJoinNum(data)
    this.joinNum = data;
end
function GuildManager.getJoinNum()
    return this.joinNum;
end

function GuildManager.getMemberInfoByPlayerId(playerId)
    if not this.unionInfo then
        return nil;
    end

    if not playerId then
        playerId = logicMgr.HeroManager.GetRoleInfo().playerId;
    end

    for _, v in ipairs(this.unionInfo.members) do
        if v.showInfo and tostring(v.showInfo.playerId) == tostring(playerId) then
            return v;
        end
    end
    return nil;
end
---------------------------工会大厅------------结束------------

---------------------------工会BOSS START--
--设置工会boss的信息
function GuildManager.setGuideBossInfo(info)
    function sortHero(a, b)
        if a["power"] ~= b["power"] then
            return a["power"] > b["power"];
        end
        if a["level"] ~= b["level"] then
            return a["level"] > b["level"];
        end
        if a["star"] ~= b["star"] then
            return a["star"] > b["star"]
        end
        if a["type"] ~= b["type"] then
            return logicMgr.HeroManager.HeroTypeList[a["type"]] > logicMgr.HeroManager.HeroTypeList[b["type"]]
        end
        return a["partnerModelId"] < b["partnerModelId"];
    end
    if this.guildBossInfo == nil then
        this.guildBossInfo = GuildBossInfo.New();
    end
    if table.getn(this.guildBossInfo.rewardsInfo) then
        this.guildBossInfo.rewardsInfo = decodeJsonStrToTabel(G.dataTable["t_guildpara"]["15"]["f_string_value"]);--奖励是恒定不变的
    end
    local data = info.unionBossInfo;
    local formation = info.formation;
    local bossId = dataTable.getDataTableByStringId("t_guildboss",data.bossId,"f_GuildBossId");
    this.guildBossInfo.bossRefreshTime = tonumber(tostring(data.nextResTime)) / 1000
    this.guildBossInfo.bossInfo = G.dataTable["t_hero"][tostring(bossId)];
    this.guildBossInfo.battleCount = data.battleCount;

    local allHeroList = {};
    for k, v in pairs(data.heros) do
        --过滤我的英雄 因为这个英雄列表之后要和本地的相加
        if logicMgr.HeroManager.getHeroDatabyPartnerId(v.heroId, true) == nil then
            local heroInfo = {}
            heroInfo.partnerId = v.heroId;
            heroInfo.partnerModelId = v.modeId;
            heroInfo.level = v.lv;
            heroInfo.star = v.star;
            heroInfo.weaponLevel = v.weaponLevel;
            heroInfo.type = HeroManager.GetHeroConfigbyModelId(v.modeId).f_HeroType;
            heroInfo.state = 0;
            heroInfo.power = v.fightVal;
            heroInfo.masterName = v.masterName;
            heroInfo.playerId = v.playerId
            heroInfo.skinId = v.skinId;
            heroInfo.icon = HeroManager.GetHeroIconByModelId(v.modeId);
            table.insert(allHeroList, heroInfo);
        end
    end
    table.sort(allHeroList, sortHero);
    local myHeroList = logicMgr.HeroManager.getOwnerHeroList(false);
    table.sort(myHeroList, sortHero);
    for k, v in pairs(myHeroList) do
        table.insert(allHeroList, v);
    end
    this.setGuideBossHeroes(allHeroList);
    this.guildBossInfo.formation[1] = {};--设置主队
    this.guildBossInfo.formation[2] = {};--设置替补队
    for i = 1, 20 do
        local teamIdx = 1;--队伍id
        local idx = i;--队内排序
        if i <= 10 then
            teamIdx = 1;
        else
            teamIdx = 2;
            idx = i - 10;
        end
        local id = tostring(formation[i]);
        if this.guideBossHeroesPartnerId[id] then
            --可以使用该英雄
            this.guildBossInfo.formation[teamIdx][idx] = tostring(id);
        else
            this.guildBossInfo.formation[teamIdx][idx] = "0"
        end
    end
end
--设置贡献榜数据
function GuildManager.setGuideBossRankInfo(info)
    this.guildBossInfo.rankInfo = info;
end
--获取工会boss的信息
function GuildManager.getGuideBossInfo()
    return this.guildBossInfo;
end
--获取当前工会boss的信息
function GuildManager.getGuideBossConfig()
    return this.guildBossInfo.bossInfo;
end
--获取公会boss伤害
function GuildManager.getGuideBossDamage()
    return this.bossDamage;
end

--清理当前工会boss的信息
function GuildManager.ClearGuideBossConfig()
    this.guildBossInfo = nil;
end

--获取工会boss的属性信息
function GuildManager.GetBossConfigByIdAndLevel(id, level)
    local cfgs = dataTable.getDataTable("t_guildbossattribute");
    for k, v in pairs(cfgs) do
        if v["f_TrialsSort"] == id and v["f_TrialsBossLayer"] == level then
            return v;
        end
    end
    return nil;
end
--获取工会boss的信息
function GuildManager.getGuideBossCfg()
    local cfg = dataTable.getDataTable("t_guildboss");
    if logicMgr.GuildManager.getGuideBossInfo() then
        if logicMgr.GuildManager.getGuideBossInfo().bossInfo then
            for k, v in pairs(cfg) do
                if v.f_GuildBossId == GuildManager.getGuideBossInfo().bossInfo.f_HeroID then
                    return v;
                end
            end
        end
    end
    return nil;
end
function GuildManager.checkIsGuildBossByModelId(id)
    local guildBossCfg = GuildManager.getGuideBossCfg();
    return guildBossCfg and tostring(id) == tostring(guildBossCfg.f_GuildBossId)
end
--通过唯一id获得英雄信息
function GuildManager.getGuideBossHeroById(id)
    --for i = 1, #this.guideBossHeroes do
    --    local hero = this.guideBossHeroes[i];
    --    if hero.partnerId == id then
    --        return clone(hero);
    --    end
    --end
    return this.guideBossHeroesPartnerId[tostring(id)];
end
--获取公会boss战所有可用英雄
function GuildManager.getGuideBossHeroes()
    return this.guideBossHeroes;
end
--获取战斗结束奖励
function GuildManager.getGuideBossReward()
    return this.bossResultReward;
end

function GuildManager.getAllNameHeroByModelId(id)
    return this.guideBossHeroesModel[tostring(id)]
end

--修改可使用英雄数据
function GuildManager.setGuideBossHeroes(data)
    this.guideBossHeroesModel = {};
    this.guideBossHeroes = {};
    for i = 1, #data do
        local hero = BattleTeamPartnerInfo.New(1);
        hero:setInfo(data[i]);
        if hero.partnerModelId then
            if this.guideBossHeroesModel[tostring(hero.partnerModelId)] == nil then
                this.guideBossHeroesModel[tostring(hero.partnerModelId)] = {};
            end
            this.guideBossHeroesPartnerId[tostring(hero.partnerId)] = hero;
            table.insert(this.guideBossHeroesModel[tostring(hero.partnerModelId)], hero)
            table.insert(this.guideBossHeroes, hero)
        end
    end
end

--修改上阵的英雄状态
function GuildManager.setHeroState(partnerId, state)
    local heroInfo = this.getGuideBossHeroById(partnerId);
    if heroInfo == nil or heroInfo.state == state then
        return ;
    end
    local modelId = heroInfo.partnerModelId;
    local modelIdHeroes = this.guideBossHeroesModel[tostring(modelId)];
    if modelIdHeroes == nil then
        return ;
    end
    for i = 1, table.getn(modelIdHeroes) do
        local hero = modelIdHeroes[i];
        if state == EnumConst.GuildStateType.Battle then
            --上阵
            if hero.partnerId == partnerId then
                hero.state = EnumConst.GuildStateType.Battle;
            else
                --除了援助上阵的
                if hero.state ~= EnumConst.GuildStateType.HelpBattle then
                    hero.state = EnumConst.GuildStateType.UnBattle;
                end

            end
        elseif state == EnumConst.GuildStateType.Normal then
            --下阵，所有同名英雄都变为可上阵状态
            hero.state = EnumConst.GuildStateType.Normal;
        elseif state == EnumConst.GuildStateType.HelpBattle then
            --替补上阵
            if hero.partnerId == partnerId then
                hero.state = EnumConst.GuildStateType.HelpBattle;
            else
                --除了援助上阵的
                if hero.state ~= EnumConst.GuildStateType.Battle then
                    hero.state = EnumConst.GuildStateType.UnBattle;
                end
            end
        end
    end
end

function GuildManager.battleCallBack(msg)
    if msg.state == 0 then
        UIWaiting.WaitingHide();
        logicMgr.GuildManager.waitMessage = false;
        this.bossResultReward = {};
        this.bossDamage = tostring(msg.damage);
        for k, v in pairs(msg.award) do
            this.bossResultReward[v.itemModelId] = tonumber(tostring(v.num));
        end
        GuildManager.RequestFightCmd(msg)
    end
end

--获得上次战斗的层数
function GuildManager.getCount()
    local curLevel = 1;
    local maxHP = 0
    while tonumber(this.bossDamage) > maxHP do
        local bossCfg = GuildManager.GetBossConfigByIdAndLevel(GuildManager.getGuideBossCfg().f_Id, curLevel)
        if bossCfg then
            local cfg = decodeJsonStrToTabel(bossCfg["f_MonsterPara4"]);
            if cfg then
                maxHP = maxHP + cfg[3][2];
            end
        end
        curLevel = curLevel + 1;
    end
    return curLevel - 1;
end

function GuildManager.RequestFightCmd(msg)
    this.autoPlayback = true;
    this.record = msg.record;

    --- 请求战斗命令
    BattlePlaybackManager.RequestReport(0, msg.fightResult, msg.record)
    BattlePlaybackManager.ResetReceiveReport()
    BattlePlaybackManager.GotoFight(EnumConst.FightTypeConst.GuildBoss)
end
--
--function GuildManager.Playback()
--    if this.fightCmdList == nil then
--        return ;
--    end
--
--    this.autoPlayback = false;
--
--    BattlePlaybackManager.setBattleRecord(this.record);
--    BattlePlaybackManager.setBattleResult(this.record.win);
--    BattlePlaybackManager.SetFightType(EnumConst.FightTypeConst.GuildBoss);
--
--    if BattlePlaybackManager.getBattleResult() == 1 then
--        logicMgr.FubenModel.SetPassTimeForLast(math.floor(HelperFunc.GetServerTime()))
--    end
--    BattlePlaybackManager.playBattle(this.fightCmdList, EnumConst.FightTypeConst.GuildBoss, function()
--        local ctrlItem = CtrlManager.GetCtrl(PanelNames.TeamHeroItem)
--        ctrlItem.CacheHeros()
--        UIBottom.closeAllUI();
--        closeUI(PanelNames.UIGuild);
--        closeUI(PanelNames.UIGuildBoss);
--        closeUI(PanelNames.UIGuildBossBattleTeam);
--    end, function()
--        UIBottom.onClickTown()
--        showUI(PanelNames.UIGuild);
--    end);
--end


---------------------------工会BOSS END

---------------------------工会砍价------------开始---------------by wangzhongyong
---获取工会砍价道具配置数据
function GuildManager.getGuildMarketSellTableDataById(id)
    if id == nil then
        return G.dataTable["t_guildinvestment"] or {};
    end
    return G.dataTable["t_guildinvestment"][tostring(id)];
end
---获取工会砍价道具名称
function GuildManager.getGuildMarketSellNameById(id)
    if id == nil then
        return "";
    end
    local data = this.getGuildMarketSellTableDataById(id);
    if data ~= nil then
        return getLanguage(data.f_StockName);
    end
    return "";
end
---获取工会砍价道具URL
function GuildManager.getGuildMarketSellIconUrlById(id)
    if id == nil then
        return "";
    end
    local data = this.getGuildMarketSellTableDataById(id);
    if data ~= nil then
        return EnumConst.AtlasPath.ICONAtlas .. data.f_StockIcon;
    end
    return "";
end

---设置工会砍价道具数据
function GuildManager.setGuildMarketSellNodeInfo(list)
    this.guildMarketSellNodeInfo = list;
end
---更新工会砍价单条道具数据
function GuildManager.updateGuildMarketSellNodeInfo(data)
    if data == nil then
        return
    end
    if this.guildMarketSellNodeInfo == nil then
        this.guildMarketSellNodeInfo = {};
    end
    for k, v in pairs(this.guildMarketSellNodeInfo) do
        if v.itemID == data.itemID then
            this.guildMarketSellNodeInfo[k] = data;
            break ;
        end
    end
end
---获取工会砍价道具数据
function GuildManager.getGuildMarketSellNodeInfo(id)
    if id == nil then
        return this.guildMarketSellNodeInfo or {};
    end
    for k, v in pairs(this.guildMarketSellNodeInfo) do
        if v.itemID == id then
            return v;
        end
    end
    return nil;
end

---设置工会砍价已用额度
function GuildManager.setGuildMarketUseQuota(data)
    this.GuildMarketUseQuota = data;
end
---获取工会砍价已用额度
function GuildManager.getGuildMarketUseQuota()
    return this.GuildMarketUseQuota or 0;
end
---获取工会砍价额度上限
function GuildManager.getGuildMarketUseLimit()
    local t_guild = G.dataTable["t_guild"];
    local lv = this.getUnionLv();
    for k, v in pairs(t_guild) do
        if v.f_Level == lv then
            return v.f_InvestmentLimit;
        end
    end
    return 0;
end

---设置工会砍价已请求助力次数
function GuildManager.setGuildMarketUseBargainCount(data)
    this.GuildMarketUseBargainCount = data;
end
---获取工会砍价已请求助力次数
function GuildManager.getGuildMarketUseBargainCount()
    return this.GuildMarketUseBargainCount or 0;
end

---设置工会砍价刷新剩余时间
function GuildManager.setGuildMarketFlushLeftTime(time)
    this.GuildMarketFlushLeftTime = math.floor(time * 0.001);
end
---获取工会砍价刷新剩余时间
function GuildManager.getGuildMarketFlushLeftTime()
    return this.GuildMarketFlushLeftTime or 0;
end

---设置工会砍价的求助列表
function GuildManager.setGuildMarketReqInfo(list)
    for k, v in pairs(list) do
        v.time = math.floor(tonumber(tostring(v.time)));
    end
    this.GuildMarketReqList = list;
end
---更新工会砍价的求助列表
function GuildManager.updateGuildMarketReqInfo(list)
    if this.GuildMarketReqList == nil then
        this.setGuildMarketReqInfo(list);
        return ;
    end
    for k, v in pairs(list) do
        for key, value in pairs(this.GuildMarketReqList) do
            if v.playerID == value.playerID and v.itemID == value.itemID then
                v.time = math.floor(tonumber(tostring(v.time)));
                this.GuildMarketReqList[key] = v;
                break ;
            end
        end
    end
end
---获取工会砍价的求助列表
function GuildManager.getGuildMarketReqInfo()
    return this.GuildMarketReqList or {};
end

---设置工会砍价交易历史信息
function GuildManager.setGuildMarketHistoryInfo(list)
    for k, v in pairs(list) do
        v.time = math.floor(tonumber(tostring(v.time)) * 0.001);
    end
    table.sort(list, function(a, b)
        return a.time > b.time
    end);
    this.GuildMarketHistoryList = {};
    local lastKey = nil;
    for k, v in pairs(list) do
        local key = os.date("%Y.%m.%d", v.time);
        if lastKey ~= key then
            table.insert(this.GuildMarketHistoryList, { day = key, list = {} });
            lastKey = key;
        end
        table.insert(this.GuildMarketHistoryList[#this.GuildMarketHistoryList].list, v);
    end
end
---获取工会砍价交易历史信息
function GuildManager.getGuildMarketHistoryInfo()
    return this.GuildMarketHistoryList or {};
end

---设置工会砍价本周盈亏
function GuildManager.setGuildMarketProfit(num)
    this.GuildMarketProfit = num;
end
---获取工会砍价本周盈亏
function GuildManager.getGuildMarketProfit()
    return this.GuildMarketProfit or 0;
end

---设置卖出时的价格
function GuildManager.setGuildMarketSellNum(num)
    this.GuildMarketSellNum = num;
end

---获取卖出时的价格
function GuildManager.getGuildMarketSellNum()
    return this.GuildMarketSellNum or 0;
end

---显示获取道具
function GuildManager.showGuildMarketHelpBargainReward(data)
    if data == nil then
        return ;
    end
    local rewards = {};
    for k, v in pairs(data) do
        local itemData = logicMgr.CostManager.getItemOrEquipDataByIdAndNum(v.itemID, v.itemNum);
        if itemData ~= nil then
            table.insert(rewards, itemData);
        end
    end
    if #rewards > 0 then
        showUI(PanelNames.UICommonItemGet, nil, nil, 3, rewards, nil, nil);
    end
end

---显示工会砍价阶段与倒计时
---1未开始,2已结束(以凌晨为分界线),3下次刷新,4下次结束
function GuildManager.getGuildMarketStateAndTime()
    local time = HelperFunc.GetServerTime();
    local temp = os.date("*t", math.floor(time));
    local toTime = os.time({ year = temp.year, month = temp.month, day = temp.day, hour = 0, min = 0, sec = 0 });
    local openTime = toTime + this.getGuildParaIntValue(4);
    local endTime = toTime + this.getGuildParaIntValue(5);
    if time < openTime then
        return 1, openTime;
    end
    if time > endTime then
        return 2, toTime + 24 * 60 * 60;
    end
    local lastTime = math.ceil((time - openTime) / this.getGuildParaIntValue(6)) * this.getGuildParaIntValue(6) + openTime;
    lastTime = math.min(lastTime, endTime);
    if lastTime < endTime then
        return 3, lastTime;
    end
    return 4, lastTime;
end
---------------------------工会砍价------------结束------------

---------------------------工会心愿------------开始------------
---
function GuildManager.getWishTipsTag()
    return this.wishChange;
end

function GuildManager.setWishTipsTag(tag, isClear)
    if this.wishChange == 1 and not isClear then
        return ;
    end
    this.wishChange = tag
end
---设置工会心愿列表
function GuildManager.setGuildWishListInfo(list)
    for k, v in pairs(list) do
        v.time = tonumber(tostring(v.time));
    end
    this.GuildWishList = list;
end
---更新工会心愿列表
function GuildManager.updateGuildWishListInfo(data)
    if this.GuildWishList == nil then
        this.setGuildWishListInfo({ data });
        return ;
    end
    data.time = tonumber(tostring(data.time));
    for k, v in pairs(this.GuildWishList) do
        if v.wishID == data.wishID then
            this.GuildWishList[k] = data;
            return ;
        end
    end
    table.insert(this.GuildWishList, data);
end
---获得工会心愿列表
function GuildManager.getGuildWishListInfo()
    return this.GuildWishList or {};
end

---设置工会心愿创建心愿次数
function GuildManager.setGuildWishCreateNum(num)
    this.GuildWishCreateNum = math.max(num, 0);
end
---获得工会心愿已创建心愿次数
function GuildManager.getGuildWishCreateNum()
    return this.GuildWishCreateNum or 0;
end

---设置工会心愿捐赠次数
function GuildManager.setGuildWishDonorNum(num)
    this.GuildWishDonorNum = math.max(num, 0);
end
---获得工会心愿捐赠次数
function GuildManager.getGuildWishDonorNum()
    return this.GuildWishDonorNum or 0;
end

---设置工会心愿捐赠记录
function GuildManager.setGuildWishHistoryInfo(list)
    for k, v in pairs(list) do
        v.time = tonumber(tostring(v.time));
    end
    this.GuildWishHistoryList = list;
end
---获得工会心愿捐赠记录
function GuildManager.getGuildWishHistoryInfo()
    return this.GuildWishHistoryList or {};
end
---------------------------工会心愿------------结束---------
---------------------------工会排行榜 开始-----------------

function GuildManager.setGuildForceRank(msg)
    this.guildForceRankList = msg.showList;
    this.selfUnionRank = msg.selfUnionRank;
end

function GuildManager.getGuildForceRank()
    return this.guildForceRankList;
end
--获取自己的公会在排行榜上排名
function GuildManager.getMyUnionForceRank()
    return this.selfUnionRank;
end

---------------------------工会排行榜 结束-----------------

-- ------------------------工会埋点----------------------
function GuildManager.SetUnionProperty(info)
    if info == nil then
        return
    end
    if this.unionInfo and this.unionInfo.id == info.id then
        return
    end
    for k, v in pairs(info.members) do
        if v.showInfo and tostring(v.showInfo.playerId) == logicMgr.HeroManager.GetRoleId() then
            TAManager.UserSet("union_job", v.jobId)
        end
    end
    TAManager.UserSet("union_id", info.id)
    TAManager.UserSet("union_name", info.name)
end

function GuildManager.Track_unionCreate(info)
    if info then
        TAManager.TrackByDictionary("union_create", {})
    end
end

function GuildManager.Track_unionJoin(info)
    if info then
        TAManager.TrackByDictionary("union_join", { union_level = info.unionOutlineInfo.lv, union_number = info.unionOutlineInfo.memberCount })
    end
end

function GuildManager.Track_unionExit(info)
    if info then
        TAManager.TrackByDictionary("union_exit", { union_level = info.unionOutlineInfo.lv, union_number = info.unionOutlineInfo.memberCount })

        if tostring(info.leader.showInfo.playerId) == logicMgr.HeroManager.GetRoleId() then
            GuildManager.Track_unionDissolve(info)
        end
    end
end

function GuildManager.Track_unionDissolve(info)
    if info then
        TAManager.TrackByDictionary("union_dissolve", { union_level = info.unionOutlineInfo.lv, union_number = info.unionOutlineInfo.memberCount })
    end
end

GuildManager.remove_playerid = nil
function GuildManager.Track_unionRemoveMember(playerId)
    if logicMgr.GuildManager.remove_playerid then
        TAManager.TrackByDictionary("union_remove_member", { player_id = logicMgr.GuildManager.remove_playerid })
        logicMgr.GuildManager.remove_playerid = nil
    end
end

GuildManager.job_change = {}
function GuildManager.SetChangeJobInfo(jobId, pid)
    GuildManager.job_change = { job_id = jobId, player_id = tostring(pid) }
end

function GuildManager.Track_unionChangePost(msg)
    local jobType = GuildManager.job_change.job_id
    if jobType == GuildManager.JOB_MEEMBER_ID then
        --成员
        TAManager.TrackByDictionary("union_repeal_vice_leader", { player_id = tostring(GuildManager.job_change.player_id) })
    elseif jobType == GuildManager.JOB_VICECHAIRMAN_ID then
        --副会
        TAManager.TrackByDictionary("union_up_vice_leader", { player_id = tostring(GuildManager.job_change.player_id) })
    elseif jobType == GuildManager.JOB_CHAIRMAN_ID then
        --会长
        TAManager.TrackByDictionary("union_change_leader", { player_id = tostring(GuildManager.job_change.player_id) })
    end
end

--UnionMarketSellNodeInfo
function GuildManager.Track_cutPriceBuy(info)
    -- if info then
        -- local t_price = info.currentPrice - info.currentPrice * (info.discountPercent / 100)
        -- TAManager.TrackByDictionary("union_cut_price_buy", { item_id = info.itemID, price = info.currentPrice, real_price = t_price, number = info.bargainNum, cost = info.averagePrice })

        -- GuildManager.Track_cutPriceSeekHelp(info)
    -- end
end

function GuildManager.Track_cutPriceSell(info)
    -- if info then
    --     local t_price = info.currentPrice - info.currentPrice * (info.discountPercent / 100)
    --     TAManager.TrackByDictionary("union_cut_price_sell", { item_id = info.itemID, real_price = t_price, cost = info.averagePrice })
    -- end
end

function GuildManager.Track_cutPriceSeekHelp(info)
    -- if info then
    --     TAManager.TrackByDictionary("union_cut_price_seek_help", { item_id = info.itemID })
    -- end
end

function GuildManager.SetCutPriceHelpId(id)
    GuildManager.help_player_id = tostring(id)
end

function GuildManager.Track_bossBattle()
    -- TAManager.TrackByDictionary("union_boss", {})
end

function GuildManager.Track_bossBattelFinish(record, level)
    local dic = {}
    dic.fight_id = tostring(record.fightId)
    dic.boss_id = tostring(GuildManager.getGuideBossInfo().bossInfo.f_HeroID)
    dic.damage = GuildManager.getGuideBossDamage()
    dic.buff_level = level
    dic.reward_level = level
    dic.duration = tostring(record.time)
    dic.role_power = tostring(record.attacker.power)
    dic.main_team = ""
    dic.sub_team = ""

    local tm = record.attacker.members
    local model_id = nil
    for k, v in pairs(record.attacker.formation) do
        if tostring(v) ~= "0" then
            for i = 1, #tm do
                if tostring(tm[i].partnerId) == tostring(v) then
                    model_id = tostring(tm[i].partnerModelId)
                    dic["pos_" .. k] = model_id
                    if k <= 10 then
                        if dic.main_team == "" then
                            dic.main_team = model_id
                        else
                            dic.main_team = table.concat({ dic.main_team, ",", model_id })
                        end
                    else
                        if dic.sub_team == "" then
                            dic.sub_team = model_id
                        else
                            dic.sub_team = table.concat({ dic.sub_team, ",", model_id })
                        end
                    end
                    break
                end
            end
        else
            dic["pos_" .. k] = 0
        end
    end
    dic.own_support_skill = record.attacker.supportSkillId
    TAManager.TrackByDictionary("union_boss_finish", dic)
end

function GuildManager.Track_cutPriceHelpOther(list)
    -- for _, v in pairs(list) do
    --     TAManager.TrackByDictionary("union_cut_price_help_other", { item_id = v.itemID, player_id = tostring(GuildManager.help_player_id) })
    -- end
end

function GuildManager.Track_wish(wish)
    if wish then
        TAManager.TrackByDictionary("union_wish_create", { hero_id = wish.heroID })
    end
end

function GuildManager.Track_wishDonate(wish)
    TAManager.TrackByDictionary("union_wish_donate", { p_id = tostring(wish.playerID) })
end

function GuildManager.Track_wishOtherDonate(wish)
    -- if wish and tostring(wish.playerID) == HeroManager.GetRoleId() then
    for k, v in pairs(wish.donors) do
        TAManager.TrackByDictionary("union_wish_other_donate", { p_id = tostring(v.playerID) })
    end
    -- end
end

-- 登录、创建、加入时调用
function GuildManager.Track_GuildSubFuncData(unionId, allianceId)
    --公会boss
    if unionId ~= nil and unionId > 0 then
        unionHandler.reqUnionBossInfo(unionId, allianceId)
        --公会战
        --unionWarHandler.reqUnionWarInfo(0)
        unionWarPlusHandler.reqGuildBattleInfo(0, EnumConst.GuildBattlePlusType.Territory)
        unionWarPlusHandler.reqGuildBattleInfo(0, EnumConst.GuildBattlePlusType.Championship)
        --军团帮助
        plunderHandler.SendGetUnionHelpInfo()
        --公会心愿
        unionWishtHandler.reqUnionWishInfo()
        --工会任务
        unionHandler.sendReqUnionTaskListInfo()
    end
    --军团科技
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Guild,false) then
        unionHandler.sendReqReqUnionTechInfo()
    end
end

--------------------------埋点 end------------------------------

--region 任务
---@return LivenessInfo
function GuildManager.IsLivenessRewardRecieved(id)
    for k,v in pairs(this.taskLivenessList) do
        if v == id then
            return true
        end
    end
    return false
end

function GuildManager.GetTaskInfoList(list,sort)
    table.clear(list)
    for k,v in pairs(this.taskInfoList) do
        table.insert(list,v)
    end
    if sort then
        table.sort(list,this.SortTask)
    end
end

function GuildManager.SortTask(a,b)
    if a.status ~= b.status then
        return a.status < b.status
    end
    return a.f_GuildTaskId < b.f_GuildTaskId
end

function GuildManager.GetTaskInfo(id)
    return this.taskInfoList[id]
end

function GuildManager.ReceiveOneTaskBoxAward(id)
    table.insert(this.taskLivenessList, id)
end

--检查是否有东西可以领
function GuildManager.CheckHasAwardGet()
    local taskIdList = {}
    local boxIdList = {}
    local hasAwardGet = false
    for k,v in pairs(this.taskInfoList) do
        if v.status == 0 then
            table.insert(taskIdList, v.f_GuildTaskId)
            hasAwardGet = true
        end
    end
    local taskBoxData = G.dataTable["t_guildtaskbox"]
    for k,v in pairs(taskBoxData) do
        if tonumber(v.f_NeedExpCount) <= this.taskLivenessCount and not this.CheckEleInList(v.f_BoxID, this.taskLivenessList) then
            table.insert(boxIdList, v.f_BoxID)
            hasAwardGet = true
        end
    end
    return hasAwardGet, taskIdList, boxIdList
end

--检查是否有东西可以领
function GuildManager.CheckEleInList(ele,lst)
    for k,v in ipairs(lst) do
        if ele == v then
            return true
        end
    end
    return false
end

--每周重置
function GuildManager.OpenTaskResetTimer(resetTime)
    if resetTime and resetTime - HelperFunc.GetServerTime() > 0 then
        local remainTime = resetTime - HelperFunc.GetServerTime()
        if this.resetTaskTimer then
            utimer.remove(this.resetTaskTimer)
            this.resetTaskTimer = nil
        end
        this.resetTaskTimer = utimer.timeCall(function()
            remainTime = remainTime - 1
            if remainTime <=  0 then
                remainTime = 0
                this.ResetGuildTaskData()
                FireEvent(Config.EventType.Fresh_Guild_Task)
                utimer.remove(this.resetTaskTimer)
                this.resetTaskTimer = nil
            end
        end, 1000, -1)
    end
end

--重置战团任务数据
function GuildManager.ResetGuildTaskData()
    this.taskLivenessCount = 0
    this.taskLivenessList = {}
    for k, v in pairs(this.taskInfoList) do
        v.progress = 0
        v.status = 1 --0:可领取 1:未完成 2:已领取
    end
end

--endregion 任务


--------------------------工会结盟----------------------
--查找联盟列表返回
function GuildManager.updateAllianceInfoList(msg)
    this.allianceInfoList = {};
    if msg ~= nil or msg.state == 0 then
        local infos = msg.unionOutlineInfos;
        for k, v in pairs(infos) do
            table.insert(this.allianceInfoList, v);
        end
        table.sort(this.allianceInfoList, function(a, b)
            if a.lv ~= b.lv then
                return a.lv > b.lv;
            end
            if a.memberCount ~= b.memberCount then
                return a.memberCount > b.memberCount;
            end
            if a.liveness ~= b.liveness then
                return a.liveness > b.liveness;
            end
            return a.id > b.id;
        end)
    end
    FireEvent(Config.EventType.Union_AllianceInfoList_S2C);
end

--获取联盟列表
function GuildManager.getAllianceInfoList()
    return this.allianceInfoList;
end

--联盟请求
function GuildManager.setAllianceRedDots()
    this.hasAllyApply = false;
end

--------------------------工会结盟 end------------------


--------------------------工会礼包 start----------------
--设置礼包服务器数据
function GuildManager.SetGuildGiftSrvData(data)
    this.giftSrvData = data.marketData.dataMap or {}
    for k,v in pairs(this.giftSrvData) do
        v.subId = k
        v.state = 1
    end
    this.SetIsNewGiftIn()
    FireEvent(Config.EventType.GuildGiftRefresh)
end

--设置礼包数据
function GuildManager.SetGuildGiftState(giftId, state)
    for k,v in pairs(this.giftSrvData) do
        if v.giftId == giftId then
            v.state = state
        end
    end
    FireEvent(Config.EventType.GuildGiftRefresh)
end

--获得可以领取奖励的礼包
function GuildManager.GetWaitToRecvGiftList()
    local tab = {}
    for k,v in pairs(this.giftSrvData) do
        if v.state > 0 and v.isReceive == 0 then
            local giftCfgData = this.giftCfgData[tostring(v.giftId)]
            if giftCfgData then
                local receiveCD = (giftCfgData.f_GuildGiftGetCd)/1000
                if v.receiveTime > 0 and  (v.receiveTime/1000) <= HelperFunc.GetServerTime() and (v.receiveTime/1000)+receiveCD >= HelperFunc.GetServerTime() then
                    v.state = 1 --等待领取
                    table.insert(tab, v)
                end
            end
        end
    end
    table.sort(tab, function(a,b)
        return a.receiveTime < b.receiveTime
    end)
    return tab
end

--获得待团长购买的礼包
function GuildManager.GetWaitToPayGiftList()
    local tab = {}
    for k,v in pairs(this.giftSrvData) do
        if v.state > 0 and v.isReceive == 0 then
            local giftCfgData = this.giftCfgData[tostring(v.giftId)]
            if giftCfgData then
                local payCD = giftCfgData.f_GuildGiftPassCd--(giftCfgData.f_GuildGiftPassCd)/1000
                if v.receiveTime == 0 and  (v.completeTime <= (HelperFunc.GetServerTime(false)+1000)) and (v.completeTime+payCD >= HelperFunc.GetServerTime(false)) then
                    v.state = 2 --等待购买
                    table.insert(tab, v)
                end
            end
        end
    end
    table.sort(tab, function(a,b)
        return a.completeTime < b.completeTime
    end)
    return tab
end

function GuildManager.GetShowGiftData()
    local recvList = this.GetWaitToRecvGiftList()
    local payList = this.GetWaitToPayGiftList()
    local showList = {}
    for k,v in pairs(recvList) do
        table.insert(showList,v)
    end
    for k,v in pairs(payList) do
        table.insert(showList,v)
    end
    return showList
end

function GuildManager.SetLastGiftData(data)
    this.lastGiftData = data
end

function GuildManager.GetLastGiftData()
    return this.lastGiftData or {}
end

function GuildManager.GetIsNewGiftIn()
    local result = this.isNew
    this.isNew = false
    return result
end

--是否有新增礼包
function GuildManager.SetIsNewGiftIn()
    if not this.isNew then
        for k,v in pairs(this.giftSrvData) do
            local find = false
            local last = this.GetLastGiftData()
            for m,n in pairs(this.GetLastGiftData()) do
                if n.giftId == v.giftId then
                    find = true
                    if not (tostring(v.fingerprint) == tostring(n.fingerprint)) then
                        this.isNew = true
                    end
                end
            end
            if not find then
                this.isNew = true
                break
            end
        end
    end
    this.SetLastGiftData(this.giftSrvData)
end
--------------------------工会礼包 end------------------



return GuildManager
